package com.hy.common.log.eventbus;


import cn.hutool.core.util.ObjectUtil;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.hy.common.utils.APIUtil;
import com.hy.entity.dto.SmsMsgReceiveDTO;
import com.hy.entity.dto.SmsMsgSendDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.EventListener;

/**
 * 系统操作日志异步操作监听
 *
 */
@Slf4j
@Component
public class SmsSendListener implements EventListener {
    @Resource
    private APIUtil apiUtil;
    @Subscribe
    @AllowConcurrentEvents
    public void listener(SmsEvent smsSendEvent){
        SmsMsgReceiveDTO receiveDTO = smsSendEvent.getReceiveDTO();
        SmsMsgSendDTO sendDTO = smsSendEvent.getSmsMsgSendDTO();
        if(ObjectUtil.isNotNull(sendDTO)){
            log.info("发送短信给审核人：{}"+ sendDTO);
            apiUtil.sendSMStoChecker(sendDTO);
        }
        if(ObjectUtil.isNotNull(receiveDTO)){
            log.info("发送短信给资产接收者：{}"+ receiveDTO);
            apiUtil.receiveSms(receiveDTO);
        }
    }
}
